/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 睡眠的线程
 * @Description *
 * @Package concurrent.mthread.join
 * @Since 2021/8/3 10:00 上午
 */
package concurrent.mthread.join;

import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;

public class Sleeper extends Thread {
    private int duration;

    /**
     * 构造
     *
     * @param name      线程名称
     * @param sleepTime 睡眠时间 秒
     * @return {@link null}
     * @author chentl
     * @since 10:01 上午 2021/8/3
     **/
    public Sleeper(String name, int sleepTime) {
        super(name);
        this.duration = sleepTime;
        start();
    }

    @Override
    public void run() {
        try {
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            System.out.println(MessageFormat.format("{0} was interrupted, isInterrupted: {1}", getName(), isInterrupted()));
        }
        System.out.println(MessageFormat.format("{0} has awakened!", getName()));
    }
}
